home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / libsrc~1.z / libsrc~1 / fputc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-28  |  759 b   |  38 lines

  1. /* from Dale Schumacher's dLibs */
  2.  
  3. #include <stdio.h>
  4. #include <sys/types.h>
  5. #include <unistd.h>
  6.  
  7. int fputc(c, fp)
  8. register int c;
  9. register FILE *fp;
  10. {
  11.     register long m;
  12.     unsigned int f = fp->_flag;
  13.     
  14.     if(f & _IORW)
  15.     {
  16.     fp->_flag |= _IOWRT;
  17.     f = (fp->_flag &= ~(_IOREAD | _IOEOF));
  18.     }
  19.     if(!(f & _IOWRT)            /* not opened for write? */
  20.        || (f & (_IOERR | _IOEOF)))        /* error/eof conditions? */
  21.     return(EOF);
  22.     
  23.     *(fp->_ptr)++ = c; fp->_cnt++;
  24.     if( (fp->_cnt >= fp->_bsiz) || 
  25.        ((f & _IOLBF) && (c == '\n'))  ) /* flush line buffd stream on \n */
  26.     {
  27.     m = fp->_cnt;
  28.     fp->_cnt = 0;
  29.     fp->_ptr = fp->_base;
  30.     if(lwrite(fp->_file, fp->_base, m) != m)
  31.     {
  32.         fp->_flag |= _IOERR;
  33.         return(EOF);
  34.     }
  35.     }
  36.     return(c);
  37. }
  38.